Rioran Tech Notes
41 subscribers
68 photos
1 file
53 links
Some notes on IT or tech staff I see along the way.
Download Telegram
#python 3.12 final version is expected to arrive in October 2023. Along other changes we are to embrace the "Syntactic formalization of f-strings", which includes:

1) Quotes reuse inside f-strings, which makes it possible to have nested f-strings further than 4 levels deep.

In my humble opinion f-strings nesting presents unnecessary cognitive complexity and should be avoided in production. Though developers decided to ignore such concerns to focus on the parser technically and wish for linters to handle the situation.

2) Multi-line expressions and comments will be allowed.

Which IMO could make complex f-strings easier to read. Though preparing it's parts elsewhere is more likely to be easier to read.

3) Backslashes inside f-strings will be allowed.

Which will make it possible to use escaping and all related mechanisms like working with the newlines or emoji (Unicode escaped sequences). Though escaped braces are still disallowed intentionally, at least "for the time being" (c).

More details could be red in PEP-701.

Reasoning behind the f-strings formalization includes:

- lowering the maintenance cost of the CPython parser;
- allowing the new PEG parser to apply improved error messages;
- making f-strings a part of the "official Python grammar" so that other Python implementations can be sure they implemented f-strings correctly;

The mechanism behind the changes introduces 3 new tokens for the parser to work with: FSTRING_START, FSTRING_MIDDLE, FSTRING_END. So, the tokenizer won't be able to produce a single token for f-strings anymore, will need more.
❤2
I have a few words about #python iterators, but my article was 400+ characters longer than the TG limit. Sooo I invite you to check out my LinkedIn post HERE.
👍1
Open Systems Interconnection
Seven layers of the Model:
Physical's for bit transmission
Data Link's for data format

Network finds the data path
Transport Layer transmits data
Using different protocols
Session is facilitator

Presentation one ensures
Data's ready for an action
Application uses network
Handles human interaction
❤2
If you are new to distributed applications - chances are you will probably follow any of those false assumptions:

1. The network is reliable.

Power failure, broken network cord, software error, message loss... There's a world of risks.

2. Latency is zero.

Even in ideal circumstances the maximum speed of information transmission is capped by the speed of light. Thus it will always take at least 30 ms to ping US from Europe and back.

3. Bandwidth is infinite.

No, STEAM doesn't load my newly acquired game in an instant. And there's also a packet loss to be considered.

4. The Network is Secure.

Top 2022 cyber security breaches include millions of users data breach of Twitter, 500M Whatsapp users phone numbers leaked, 50K Revolut users personal information exposed.

5. Topology doesn't change.

Dynamic IPs, CI/CD processes, databases sharding/replication, moving servers, clients changing devices & networks and that's only a top of the iceberg.

6. There is one administrator.

Live of your application depends on multiple parties. Whether it's external vendor or your fellow college - probably the occasion will come for you to solve an issue you are restricted to solve on your own.

7. Transport cost is zero.

You will inevitably pay. Time and resources for going between the application and transport level. Money for routers, network security, internet connections, electricity, etc.

8. The network is homogeneous.

Across almost every organization I saw operating systems being split by Miscrosoft & Linux, different processor architectures like x86, x64, and don't even mention the diversity of mobile devices. Do they work the same?

Fallacies were introduced by Peter Deutsch (first seven) & James Gosling (the eighth) in late 90s. I took some inspiration in Arnon Rotem-Gal-Oz paper. And added my personal perspective on examples.

#architecture #design
👍2🔥1
#selenium provides the easiest way to get cookies with #python
❤1
One of the key concepts of #python is the concept of callable.

Callable is an object that can be called. Basically, all of those are callables: user-defined functions, instance methods, generator functions, coroutine functions, async generator functions, built-in functions, built-in methods, classes and class instances.

In order to be a classic callable - you need to have a dunder method "call" to be defined. As it is in my short demo code on the attached image.

I make a custom class inheriting all there is from the float class. And I add the only method of the topic - the call dunder. For fun sake upon using our object as function - we will return a float times the specified number. In order to return our Callable_Number other than the float - we need to also modify the multiplication dunder. Which is now by default returns the float type.

On the line 5 we initiate our class. By the way, we are calling the class to get it's instance. That's how classes themselves are callable. And we get our Callable_Number object as the result. The following print statement clearly shows the float value and the existence of the call dunder, thanks to the callable built-in function.

On the line 7 we CALL the "a" object, an INSTANCE of our class. That's where the call dunder is activated. Thus the multiplication as a result. As you see - our newly created "b" object lacks the call dunder. Since it is a usual float due to the mechanism I described previously.

Useful links:

1 - callable built-in function https://docs.python.org/3/library/functions.html#callable
2 - datamodel with callable types described https://docs.python.org/3/reference/datamodel.html
3 - expressions reference on calls https://docs.python.org/3/reference/expressions.html#calls
4 - C-API call protocol https://docs.python.org/3/c-api/call.html
The way I like my imports to be refactored in #python - is for them to be grouped and each name on a single line. It is highly readable, less prone for errors.

A simple way to refactor imports - is to use the isort library. I prefer to utilize the following flags:

mode 3 - stands for VERTICAL_HANGING_INDENT

force grid wrap 2 - to start grid wrapping with only 2 imported names

trailing comma - so that all lines are similar

With some shortcuts the final command looks like this:

isort file-name.py -m 3 -fgw 2 -tc

You can edit the isort config file in order to NOT TO use all those flags each time. For these and other helpful details you can always refer to the isort official documentation: https://pycqa.github.io/isort/index.html
Finally got my hands on the Jupyter Notebook 7. Whoa, I like those new features!

Here is my screenshot with the debugger and table of contents pane out of the box. Nice and clean! And those just scratch the tip of the iceberg!

Though, not everything is ideal. Some users, me included, could face difficulties to upgrade Notebook 6 to 7 from the Anaconda Navigator on Windows machine. Pity, I do love the Anaconda Distribution. So, terminal is our best friend. Install:

pip install jupyter
pip install notebook

And run:

jupyter notebook
Here is a nice library to be aware about: https://pypi.org/project/python-dotenv/

Python-dotenv reads key-value pairs from a .env file and can set them as environment variables. It helps in the development of applications following the 12-factor principles.
Hey, dear #python enthusiasts, PyPI just went through a public audit! A huge masterpiece report can be found in the Trail Of Bits repository . Shortly: 8 medium and 6 low severity exposures, low test coverage, but overall all is good.
By the way, did you know that you can unpack strings with multiple assignment in #python ?
🔥3
A must-have technique for a huge or feature-rich application - feature flags. It is a great way to control your project without the need to redeploy. You decide what parts of the project you want to work and in what way, remotely and smoothly.

Here is a well written entry article for the topic.
❤1👍1🔥1💯1
tempfile - a nice built-in Python library to create temporary directories and files. You can use those tmp objects directly in Python or in complex scenarios like execution of a terminal command with BashOperator inside Airflow DAG.

Official docs: https://docs.python.org/3/library/tempfile.html

Example:

from tempfile import NamedTemporaryFile


with NamedTemporaryFile('w') as file:
file.write('Roman\nRioran\nVoronov\n')
file.flush()
print(f'{file.name = }') # file.name = '/tmp/tmpbrotweh8'
with open(file.name, 'r') as tmp_file:
print(f'{tmp_file.readlines() = }') # tmp_file.readlines() = ['Roman\n', 'Rioran\n', 'Voronov\n']
Channel photo updated
Several years ago during my analyst work in Yandex I regularly performed SQL related tasks via one hell of an internal tool. Not sure if NDA allows me to announce its internal name. But! Lo and behold - a huge and powerful part of that tool is now publicly released as YTsaurus! As I see it - the name is a mix of several geek words like "thesaurus" including one internal joke.

Just check out the number and quality of those features! https://ytsaurus.tech/

This tool allowed me to perform intensive and complicated calculations over billions of samples of user activity data in Taxi service.
👍3