Data Type Enforcement at Runtime Level in Python

Such a wild dream, isn't it?

Python is quite dynamic. Variables can reference strings, then lists, then sets... It's an intrinsic characteristic of the language.

I was there, thinking that it could be possible. Never found a safe trail for achieving this, and for a long time, I thought it was just me. Some think that Type Hints could be a starting point of having such feature, without understanding the concept of Type Hints and annotations.

Some people might think that Data Classes could provide some solution, and nope: Data Classes are just a more elegant way of creating Classes, implementing __init__ and __repr__ methods by default, among other functionalities, but still, it does not take care of type enforcement at runtime level.

The best that you could have is type enforcement at instantiation level, being a Data Class or not, but still, you can pass the expected data while creating the object, later on changing the instance variable, without any validation penalty:

Pydantic does this kind of type enforcement gracefully at object creation, not runtime:

It's unlikely to happen in the near future, to be honest. And if it happens, it would be a great change for the specification of the language. Data type enforcement is a great advantage in compiled languages (not our case here), then accidents of defining an integer to a char type variable, not being allowed by the compiler.

To keep a variable consistent in regards with its data type, is something we must do by default while developing in Python. IDEs and linters can help on that. And that's the best that you can have.

I shared something on this thread a couple of weeks ago:

If type enforcement at runtime level is something you really need on your project, you need a different programming language, considering the trade-offs of not using Python.

It would be nice to have such thing in Python, one day. Hope that it will not remain as a wild dream that we all kind of have.

Walking Early in the Morning : A Complete RESET

Intro to Reality


During the COVID-19 pandemic, I worked with an experienced Engineer. He worked several years for Hewlett-Packard, mentioning that it was for him a habit to start his day with a long walk, at 06 AM.

I thought it didn't had any particular benefit. Maybe some sort of practice that became necessary during that period, where we all suffered with social distance, isolation, etc., I thought to myself.

Since then, the idea was buzzing. Working remotely, spending a lot of time with virtual connections, disconnected from the outside: it's not a good thing. Could it be something beneficial?

Encountering more and more complex problems and questions, requiring good answer and explanations, from personal to professional matters.

I wish I could have a scientific background while writing this. This is just me, describing my experience, effects in my life.


First Steps (2023)


Start walking once or twice in a week. 07:00 AM. The fresh air. Few people on the streets, and some cars. Office workers starting their days, taking their kids to the schools.

There I was, having a 15 minutes route on a local park, which resembles more of a sunken forest, with different paths inside of it, where people take their dogs for a walk. Close to an avenue, and in a peaceful neighborhood.

Quite positive, but still, it was hard to establish a routine, specially when you live with someone who is not an early bird. It was more of an event, infrequent. You might feel like you have to do many things together, but that is more of a myth, and this experience, made that clear to me.


Nowadays (2024)



Times changed and so the circumstances (and the needs too). Now, I have long and frequent walks, starting at 06:30 AM. It became a necessary and healing routine. Going to the gym is great: it also reduces stress levels. But its not like walking.

I prepare myself a coffee to take with me. Comfortable clothing. Sun is rising: comes a sensation of synchronicity, as if something was also rising on my mind.

Some inspiring music or a podcast. It's like giving something easy for your brain to play with, while you observe the life outside. Listening to David Bowie while watching the kids going to school, it works just fine: the human equation is indeed, something complicated to understand.

If something works for you and you validated it, then it works.


RESET Completed

Back home, everything is more clear. A feeling of presence and awareness, which I tried to breakdown on the following paragraphs:

Connection

Could it be walking in the morning a kind of meditation? Not rushing things? I feel more connected with myself, more aware, by knowing what is going on "outside of my cave" (other realities). A sense of complete presence.


Reasoning

Designing solutions or thinking in possibilities (unfolding), is a more soft process. Reflections upon strategies, look more clear than before, reconsidering decisions and standpoints from yesterday, some of them (eventually) surprising me, in a positive way.

More pragmatism, then reducing noise. Breaking down complex things into small parts (more Cartesian), doing things that matter, first. No pressure of tackling multiple things.

Some of them, can't be handled right now, and that's OK.

Every issue, will have its turn to be solved.


Organism

I have to mention this: digestive apparatus works way better. For someone that spends too much time sitting on a desk, you might imagine how difficult this topic could be (e.g.: IBS).

I dare to say that, even the breakfast, tastes better. Senses are sharpened.


Relaxation 

Now that have more awareness from outside, with a completed RESET process, I am more relaxed. There's more room for reason and comprehension, rather than assumptions and early judging. If every human being holds a universe inside, I feel that such universe, moves more gentle.

Feelings of anxiety or worries, become weaker, even ceasing to bother. Peace and self control, are boosted.


Writing

Being code, documentation, writing things with more meaning, is also experienced. Communication is more fluid in all vectors.


Wrap Up : The Reset Process & A Compound Interest of 1%

I'm aware that, social, economic and even environmental aspects, might pose severe restrictions for such a simple activity. You might require someone to be your partner, if that's the case. Taking your dog with you on, your wife/husband (if you don't want to/cannot walk alone), could be something to improve the experience.

Dryer places, might provide a different experience in comparison with tropical regions, but the "magic" of walking outside, still happens.

Effects you might experience, are pretty much related with your openness to enjoy the process, although I'm not so sure if you will harvest the best of it, if you are thinking about getting back to your house ASAP, without even having a good reason for it: some autopilot which you haven't detected, yet. In such case, there'll be no meditation, I'd say: it's not just about walking in the morning, but it's also about starting your day and connecting with the world outside.

Then, you might have a complete reset process which started at the end of the last day, after having a good night of sleep (crucial), then finishing with a long walk, early in the morning.

I'm confident that it's a habit that gives 1%, every time you do it. Think it like a compound interest: imagine the long-term effect on you, even on those around you, experiencing your best version, more relaxed and present, in the long term.

Hope you might think it over, even if you are not an early bird.

"The 1% that makes the difference."


Xinantécatl (Nevado de Toluca)



The 4th highest mountain peak (4680m) in Mexico, Xinantecatl (The Naked Lord), often called "Nevado de Toluca". Many agencies offer trips to visit the "Lagunas" (of the Sun and Moon), but few offer the experience of hiking/climbing until you reach its summit.

Here's a narrative of my experience. I never hiked and climbed anything higher than 1000m.

Something around 11 hours of trekking (some parts of climbing). A journey that I truly recommend.



Arrival, but not yet



I spent the night without sleep. Transport wasn't that comfortable. I was a bit anxious about the journey, about not being prepared with good clothing, the low temperatures. I wasn't so sure of my endurance in such conditions, to be honest.

During the winter, temperatures vary between -8ºC to 0ºC. 

After the preparation for the hiking on the base of the park, we moved to the road that serves as entrance to the base of Xinantécatl. Some vans transport you, from the entrance to the base of the park. 3 USD.

Good socks, clothes with thermal insulation, good boots, gloves, are much welcome. Without it, you will shiver. In my case, I forgot to bring a beanie, gloves, sunglasses, and they were all missed...

Bring cereal bars, fruits, sandwiches and water (2L) on your backpack.

06:20



Beginning



The horizon and the mountains around, form beautiful landscapes.



It's like another planet. Mars kind of thing.
7:17, at the entrance of the trail to Xinantecatl, the temperature is of -2º C.
As the time goes by, temperature increases, slowly.


Our guide warn us about Altitude Sickness, asking us to report any health condition or incident.

He mentions about the importance of taking breaks, getting used with the altitude, to administer our energies. Step by step, is the best strategy.



The trail from the entrance until the crater, was part of a warm-up.
Your heart pumps a bit more. Breath becomes more intense.



Hard to describe how it feels to be there. It's a state of peace, hard to find in other places.



The Crater



08:00 o'clock. Several people gathered around, taking photos of Xinantécatl, admiring the view, planning their descent to the lakes of the Sun and the Moon.






We descended on the left side of the crater. Finishing our warm-up.
Then, the journey begins, until the highest of the 4 peaks you see from the top-middle to the top-right.



Crossing the Crater


08:40. I thought that the second peak was the summit.
Altitude and terrain might deceive your predictions.




Mountain Sickness is always present, although we kept a good pace.


It never ends, the beauty of the landscapes.

The higher we hike, the beautiful it gets. It's just refreshing.


09.17. Difficulty increases. Mountain Sickness...

Breaks are much necessary, as well as staying hydrated and eating, for beginners (as I) or seasoned hikers. 




First Peak


A different sight can be seen near the first peak.
The flora is unique, yet beautiful. Nearby the crater, you can spot 
some plants that are almost dry, apparently dead.




Getting closer to the peaks, temperatures are very low, concentrating humidity (sometimes with snow), with a lot of sun. You can see some types of succulents, and even these flowers.

It's 10:11.



The slope increases and helmets are now required. Now, it's climbing instead of hiking. 
The flora persists, gently and resilient, at an altitude of ~3800m.



Second Peak


The terrain demands more resistance and concentration... 



It's 10:39.



"Laguna del Sol" was getting far and far away.

The cliff of the second peak, imposes respect, showing the danger of not paying attention to where you step or grab. Stay sharp and inclined against the slope, step by step, and you'll be alright.



The terrain gets rockier than ever and snow starts to show. Never stop over it, for you might slip.

It's 11:10.





5hs of hiking and climbing. Close to the summit.
The nature here, constantly rewards you with this kind of sights.

4200m.

It's 11:37.



Third Peak


The trail here is a bit gentle than usual, letting you hike instead of climb.

Cliffs, are more present than ever. The terrain is full of giant rocks, impossible to move with two or more individuals over it.

The picture from the right looks menacing, but even beginners can climb these slopes, with attention, patience, and a bit of physical condition.

12:10.



Last Peak (more cooperation)



We were starting to feel tired, wanting to reach the summit.

We stood sharp than ever, watching who is climbing in front of you, warning the others behind you about rocks that were not safe to grab or step. Eventually, we were pushing and praising each other.



Behind of us, the peaks and some cliffs, showing us how long we have been climbing and hiking, far away from our starting point. The landscape keeps impressing.

It's 12:25.



The Summit



Finally, we made it.

I wish I could stay on the summit for a good amount of time. There were a lot of people climbing, and you couldn't stay that long, especially if you don't want to fall behind of your group. 




Xinantecatl's summit, called "Pico del Fraile". 4680m.

It's kind of surreal, yet peaceful. One feel so tiny there.

How many mountains one must climb on this life? How many trails? How much one needs to endure in order to reach the summit of something?

Pride, social status, preferences, human stuff, are all small in comparison with the nature and it's magnitude.




12:45.



Descent (challenge)


Time to descent, and the conditions are not that optimal.

Toughest part of the journey

40 minutes of break, after 6 hours and half, between climbing and hiking.

I was quite tired at this point. More than 24 hours without sleep, takes its toll...

It's 13:27.




The trail...

The terrain is very slippery, unstable. I wasn't carrying a hiking staff, or using the appropriate shoes for hiking. It's completely normal to fall here, but be sure to fall in the middle of the trail: there are a lot of slopes and ravines, with hundreds and hundreds of meters down below.

This part of the journey is a bit stressing, but manageable.



I almost fell to my knees, near the ravine... 



The terrain gets easier, with more rocks and less instability. Still, watch your steps.
Stay hydrated, eat some fruit. There's still at least 2hs of descending...

It's 14:25.



Landscapes are not bad, are they?

We passed the more menacing part of the trail.
Not so much slopes. Terrain is very stable. You can even see the forest down there, final part of the journey.




It's an one of a kind nature...

It's 14:45.




Forest up ahead. Getting closer to the end of the journey.

It's 15:15.




Different nature here, although the air is clean, just as up there.
I'd say even better than up there, since it's filled with pine trees, acacias.



We just followed one of the several trail that the forest has to offer.

We moved from a not so friendly descent, to this peaceful surrounding. You can even hear birds singing, and some woodpeckers.  



End of the journey.

16:10.

The weather is still pleasant. At this point, I can hardly believe on all we went through. I guess I've never went through a situation like this.

We stood together. Everyone reached the summit. You may do the whole thing alone but, in a team, you stay stronger, supported.

Oddly enough, while climbing to the summit, I didn't felt stressed, not even when looking at the cliffs, or when trying to find the right rock to grab or step in.

Different story was the descent.




The nature, still, so gentle and calm here as well.



Celebration



One of our guides, Chopes, took us to a countryside kitchen, good food and cheap, 15 minutes away from "Parque de Los Venados".

He paid a beer for us, congratulating us for the endurance after the whole "chinga" that we went through. He's a quite an experienced and humble individual. He knows Nevado de Toluca National Park like the palm of his own hand, climbing Xinantécatl's many times, just as Citlatépetl (Pico de Orizaba).

Trustworthy and friendly individual, indeed.

17:33

 


Final Words

Just as this journey, is life itself. We have to endure, to persist, to administer our resources, to concentrate on the present moment, on the process.

There isn't such thing as, having marvelous progress, all of sudden. You may try to run, rushing. You'll only get tired, consuming you energy. Compromising your progress. Several and several steps to be taken if you want to reach the summit, isn't it? 

When you are at the summit, you can't measure the mountain. You're just there, admiring the landscape, feeling peace, being grateful to yourself for conquering your resistance.

But only when you descend, then you can observe the mountain. Understand where you were, what you went through.

Now, you understand...


----

In case you want to get in contact with Chopes for his guiding services, here's his facebook.
The agency which offered this experience to us, is Veracruz Adventure.


Mastodon