Question on ABC classes
On 2020-10-22 23:35:21 -0700, Julio Di Egidio wrote:
> On Friday, 23 October 2020 07:36:39 UTC+2, Greg Ewing wrote:
> > On 23/10/20 2:13 pm, Julio Di Egidio wrote:
> > > I am now thinking whether I could achieve the "standard"
> > > behaviour via another approach, say with decorators, somehow
> > > intercepting calls to __new__... maybe.
> > I'm inclined to step back and ask -- why do you care about this?
> > Would it actually do any harm if someone instantiated your
> > base class? If not, then it's probably not worth going out
> > of your way to prevent it.
> This is the first little library I try to put together
> in Python, and it was natural for me to hit it with all
> the relevant decorations as well as type annotations in
> order to expose *strict* contracts, plus hopefully have
> intellisense work all over the place.
I think you are trying to use Python in a way contrary to its nature.
Python is a dynamically typed language. Its variables don't have types,
only its objects. And basically everything can be changed at runtime ...
It now has type annotations, but they are ignored both by the compiler
and at run-time. They are only for the benefit of linting tools like
mypy and editor features like intellisense.
> and the whole lot, indeed why even subclass ABC?
Good question. In six years of programming Python, I've never used ABC.
But then I came from another dynamically typed language to Python.
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 833 bytes
Desc: not available