Dataclasses and property decorator

It sure does work: from dataclasses import dataclass @dataclass class Test: _name: str=”schbell” @property def name(self) -> str: return self._name @name.setter def name(self, v: str) -> None: self._name = v t = Test() print(t.name) # schbell t.name = “flirp” print(t.name) # flirp print(t) # Test(_name=”flirp”) In fact, why should it not? In the end, what … Read more

Installing Python3.6 alongside Python3.7 on Mac

Try using brew for example if already using Python 3: $ brew unlink python Then install python 3.6.5: $ brew install –ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb To get back to python 3.7.4_1 use: $ brew switch python 3.7.4_1 And if need 3.6 again switch with: $ brew switch python 3.6.5_1

“RuntimeError: generator raised StopIteration” every time I try to run app

To judge from the file paths, it looks like you’re running Python 3.7. If so, you’re getting caught by new-in-3.7 behavior: PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions raised directly or indirectly in coroutines and generators are transformed into RuntimeError exceptions. (Contributed by Yury Selivanov in bpo-32670.) Before … Read more

Will OrderedDict become redundant in Python 3.7?

No it won’t become redundant in Python 3.7 because OrderedDict is not just a dict that retains insertion order, it also offers an order dependent method, OrderedDict.move_to_end(), and supports reversed() iteration*. Moreover, equality comparisons with OrderedDict are order sensitive and this is still not the case for dict in Python 3.7, for example: >>> OrderedDict([(1,1), … Read more

Data Classes vs typing.NamedTuple primary use cases

It depends on your needs. Each of them has own benefits. Here is a good explanation of Dataclasses on PyCon 2018 Raymond Hettinger – Dataclasses: The code generator to end all code generators In Dataclass all implementation is written in Python, whereas in NamedTuple, all of these behaviors come for free because NamedTuple inherits from … Read more

Class inheritance in Python 3.7 dataclasses

The way dataclasses combines attributes prevents you from being able to use attributes with defaults in a base class and then use attributes without a default (positional attributes) in a subclass. That’s because the attributes are combined by starting from the bottom of the MRO, and building up an ordered list of the attributes in … Read more

What are data classes and how are they different from common classes?

Data classes are just regular classes that are geared towards storing state, rather than containing a lot of logic. Every time you create a class that mostly consists of attributes, you make a data class. What the dataclasses module does is to make it easier to create data classes. It takes care of a lot … Read more