🇺🇦 Python Programming Сhallenges
1.04K subscribers
3 photos
2 files
63 links
Размышления на тему решения различных задач по спортивному программированию на Python и не только.
加入频道
Import Linter allows you to define and enforce rules for the imports within and between Python packages.

[importlinter]
root_package = myproject

[importlinter:contract:1]
name=Foo doesn't import bar or baz
type=forbidden
source_modules=
myproject.foo
forbidden_modules=
myproject.bar
myproject.baz


Example output:
=============
Import Linter
=============

---------
Contracts
---------

Analyzed 23 files, 44 dependencies.
-----------------------------------

Foo doesn't import bar or baz BROKEN

Contracts: 1 broken.

https://import-linter.readthedocs.io/en/stable/readme.html
beta preview of Python 3.9 is out:

- PEP 584, Union Operators in dict
- PEP 585, Type Hinting Generics In Standard Collections
- PEP 593, Flexible function and variable annotations
- PEP 602, Python adopts a stable annual release cadence
- PEP 615, Support for the IANA Time Zone Database in the Standard Library
- PEP 616, String methods to remove prefixes and suffixes
- PEP 617, New PEG parser for CPython

https://www.python.org/downloads/release/python-390b2/
Restructuring data, the Python way.

>>> import glom
>>> glom.assign({}, "a.b.c.d", 42, missing=dict)
{'a': {'b': {'c': {'d': 42}}}}

# Path-based access for nested structures
>>> target = {'a': {'b': {'c': 'd'}}}
>>> glom(target, 'a.b.c')
'd'

happy glomming! 😋

https://glom.readthedocs.io/en/latest/
Forwarded from 🇺🇦 Go for two :)
Note #68: The Rules of Optimization Club

1. You do not optimize.
2. You do not optimize, without measuring first.
3. When the performance is not bound by the code, but by external factors, the optimization is over.
4. Only optimize code that already has full unit test coverage.
5. One factor at a time.
6. No unresolved bugs, no schedule pressure.
7. Testing will go on as long as it has to.
8. If this is your first night at Optimization Club, you have to write a test case.

from https://wiki.c2.com/?RulesOfOptimizationClub
PEP 622 -- Structural Pattern Matching

Interesting proposal for python 3.10.

The proposed indentation structure is as following:
match some_expression:
case pattern_1:
...
case pattern_2:
...


and example from pep:
match number:
case 0:
print("Nothing")
case 1:
print("Just one")
case 2:
print("A couple")
case -1:
print("One less than nothing")
case 1-1j:
print("Good luck with that...")


https://www.python.org/dev/peps/pep-0622/
Asynchronous IO Support for Core and ORM

SQLAlchemy 1.4
now supports Python asyncio-compatible database drivers using an all-new asyncio front-end interface to Connection for Core usage as well as Session for ORM use, using the AsyncConnection and AsyncSession objects.

https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#asynchronous-io-support-for-core-and-orm
Forwarded from 🇺🇦 Go for two :)
Note #71 The seven rules of a great Git commit message

1. Separate subject from body with a blank line
2. Limit the subject line to 50 characters
3. Capitalize the subject line
4. Do not end the subject line with a period
5. Use the imperative mood in the subject line
6. Wrap the body at 72 characters
7. Use the body to explain what and why vs. how

https://chris.beams.io/posts/git-commit/
Hypermodern Python 👩‍🚀 🐍

Chapter 1: Setup
Chapter 2: Testing
Chapter 3: Linting
Chapter 4: Typing
Chapter 5: Documentation
Chapter 6: CI/CD

https://cjolowicz.github.io/posts/hypermodern-python-01-setup/
I can't recall where I saw this originally, but you can use the spaceship operator "--0--" to turn floor division into ceiling division:

>>> 12//5
2
>>> --0-- 12//5
3

There's also the ++0++ operator when you want to emphasize that you really *do* mean floor division:

>>> ++0++ 12//5
2


from https://bugs.python.org/issue43255#msg387248
But yes, -(-n // d) is the easy (if a little bit cryptic) way to get the ceiling of n / d.
Forwarded from 🇺🇦 Go for two :)
How to Make Your Code Reviewer Fall in Love with You:

1. Review your own code first
2. Write a clear change list description
3. Automate the easy stuff
4. Answer questions with the code itself
5. Narrowly scope changes
6. Separate functional and non-functional changes
7. Break up large change lists
8. Respond graciously to critiques
9. Be patient when your reviewer is wrong
10. Communicate your responses explicitly
11. Artfully solicit missing information
12. Award all ties to your reviewer
13. Minimize lag between rounds of review

https://mtlynch.io/code-review-love/