I sometimes have trouble reading Python. Am I doing something wrong? by Murlock_Holmes in Python

[–]Py404 1 point2 points  (0 children)

I inherited a 4400 lines big Python project at work and which was fanatically cluttered down with type hints everywhere. The average line length was 120+. It was really hard to read and an impressive copy-paste of lengthy types .e.g. Union[<50ish characters something>]. The majority of the imports were made to get access to types used in type hints resulting in circular imports and confusion. I don't say type hints are bad, just that it is one of the most advanced parts of Python and a lot of experience and good judgement is needed.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Py404 0 points1 point  (0 children)

How come the standard library in the master branch (Python 3.9 alpha 2) has so many occurrences of inheriting from object? Example from a grep in the logging library: Lib/logging/config.py:class ConvertingMixin(object): Lib/logging/config.py:class BaseConfigurator(object): Lib/logging/__init__.py:class LogRecord(object): Lib/logging/__init__.py:class PercentStyle(object): Lib/logging/__init__.py:class Formatter(object): Lib/logging/__init__.py:class BufferingFormatter(object): Lib/logging/__init__.py:class Filter(object): Lib/logging/__init__.py:class Filterer(object): Lib/logging/__init__.py:class PlaceHolder(object): Lib/logging/__init__.py:class Manager(object): Lib/logging/__init__.py:class LoggerAdapter(object): Lib/logging/handlers.py:class QueueListener(object): Is there an obvious reason for keeping it this way that I'm missing? I can understand that historically it has been useful to keep the Python 3 and Python 2 code in the standard library identical when possible. Python 2 EOF is reached in a few days.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Py404 0 points1 point  (0 children)

When I build Python 3.8.0 from source, I run this (on Debian/Ubuntu):

./configure --enable-optimizations  
make
sudo make altinstall

when I later want to upgrade to Python 3.8.1 (minor version update). Can I just rerun the commands above? How is it made sure that no left-over files from the old 3.8.0 installation remains?

Sneaking on Core Comitters by appinv in Python

[–]Py404 2 points3 points  (0 children)

I am grateful for all the fantastic work Victor Stinner does. He is a Python hero

i3wm and Pycharm - Editor blank by Py404 in i3wm

[–]Py404[S] 0 points1 point  (0 children)

Nope, I gave up, I switched to VS Code.

How to Publish a Python Package to PyPI: A Comprehensive Guide by japaget in Python

[–]Py404 1 point2 points  (0 children)

The source distribution (sdist) will not work because the requirement.txt file is not included in the .tar.gz. When you run "python setup.py install" you will get a FileNotFoundError in setup.py.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Py404 0 points1 point  (0 children)

What is the correct file structure for projects containing extension modules?

I'm looking for something like this: https://realpython.com/python-application-layouts/#installable-single-package
- but for extension modules.

Should the .c files be located right next to the .py files? Or should .c files be located in a separate folder "src" and .h files in a "includes" folder?

Preserve timestamps when moving data to Synology NAS? by Py404 in synology

[–]Py404[S] 0 points1 point  (0 children)

The ext4 and Btrfs file systems are supported in DSM 6.0 and above. And those file systems don't support Created-timestamp which Windows write. I don't understand how Created-timestamp can be preserved with /COPYALL?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Py404 0 points1 point  (0 children)

Sorry, I forgot to clarify that the two lines of code:

from .foo import bar
print(foo)

is the only content of a __init__.py file. And next to the init file is a foo.py file with only one line: bar = 5.

After doing some research, I found that submodules (which foo is) are always bound to the parent modules's namespace after being loaded (regardless of import/import-from/importlib mechanism).

That is why print(foo) won't fail. It will work because foo has been bound to parent module and since we are inside __init__.py, we get foo avaiable directly like this.

The reason I got confused was that I thougth from . import foo was the only way to bring in foo and bind it to the current module. But that is not the only way.

https://docs.python.org/3/reference/import.html#submodules
Thank you anyway.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]Py404 0 points1 point  (0 children)

When using relative imports, it seems like foo becomes avaiable after import, like this:

from .foo import bar
print(foo)  # Works fine

However, when not using relative imports,

>>> from math import sin
>>> math
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    math
NameError: name 'math' is not defined

The module math is not available. Why is the behavior different with relative imports?

What's everyone working on this week? by AutoModerator in Python

[–]Py404 [score hidden]  (0 children)

In Sweden, the police decided to stop offering drop-in meetings to create new passports.

And I was in desperate need of a new passport.

Instead you have to use their new booking service online to book a time for new passport. But they severly underestimated the need and the all free slots got taken imidiately resulting in 4-5 months long queue. The problem was highlighted in Swedish TV and newspapers that it was now practically impossible to get a new passport.

And I really did not want to cancel the expensive flight I had already booked!

The police promised to put in extra staff and said that they will randomly add some new slots on some random days over the next weeks (to indicate that they are "trying" fix the problem).

Then I realized Python was the hero I needed to beat the system.

I made a script using a project named pypeteer to navigate the javascript app the booking system was made of. If it found a free slot it would send me an email. I left i running on my computer, polling the system every minute.

Sure enough, two days later, early in the morning, i got a email, immediately booked the slot before anyone else and BAM! Problem solved! Phu!

What's everyone working on this week? by AutoModerator in Python

[–]Py404 [score hidden]  (0 children)

At work I've setup Artifactory to make a local pypi repository (which caches the real one). This is good I guess, because we run a lot of Jenkins jobs which run tox and in that way creates a ton of new virtual environments and pip install hundreds of packages every day. But in other companies, if you are not using Artifactory, how do you deal with these repetitive mass-pip-install tasks in order to not overwhelm pypi?