[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Random832
On Fri, Aug 21, 2020, at 21:52, Steven D'Aprano wrote: > Having said all that, I cannot help but feel that shadowing of modules > is such an issue that maybe we need to make a special case of this. Not > specifically tkinter, of course, but if a module attempts to directly > import a module with

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Random832
On Sat, Aug 22, 2020, at 03:09, Random832 wrote: > > AttributeError: partially initialized module 'spam' has no attribute > > 'egsg' (most likely due to a circular import) > > > > If the error wasn't due to shadowing or a circular import, then knowing > > that I had misspelled 'eggs' would be ve

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
I think you have some really valid points in your answer, Steven. To me, it seems like we have two main options to improve the message for shadowing modules. I copied part of your and Random832’s answer here, since they summarize it quite nicely: 1. If a module attempts to directly import a mod

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Steve Barnes
Couldn’t the whole issue potentially be avoided with some meta-modules, e.g.: from STDLIB import sys from STDLIB.os import path from LIBS import pandas as pd from LOCALS import path # This should cause an error from LOCALS import path as mypath # this not This would leave the current import synt

[Python-ideas] Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Oz
Hi Everyone, I really like how go parses durations: ``` hours, _ := time.ParseDuration("10h") complex, _ := time.ParseDuration("1h10m10s") micro, _ := time.ParseDuration("1µs") // The package also accepts the incorrect but common prefix u for micro. micro2

[Python-ideas] raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread rawmin . rx
I wanted to know if there could be TypeError when giving wrong type for arguments in functions (This usually happens when using other module's function) e.g: def sum(nom1: int, nom2: int): nom = nom1 + nom2 return nom print(sum('hello',2)) if you run this code you will get TypeError f

[Python-ideas] raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread rawmin . rx
I wanted to know if there could be TypeError when giving wrong type for arguments in functions (This usually happens when using other module's function) e.g: def sum(nom1: int, nom2: int): nom = nom1 + nom2 return nom print(sum('hello',2)) if you run this code you will get TypeError f

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Alex Hall
I think the most popular library for this is typeguard: https://github.com/agronholm/typeguard I've also seen a couple of other similar libraries: https://github.com/FelixTheC/strongtyping/issues/33 https://github.com/seandstewart/typical/issues/24 On Sat, Aug 22, 2020 at 3:01 PM wrote: > I w

[Python-ideas] Re: Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread tcphone93
I would very much welcome this to the standard library as it seems like a useful function; I certainly would make good use of it and I'm sure others working with durations use similar code for user-facing parts. > With a go like parsing it would be: > >>> datetime.parse_duration("2w50d8h5m27s10m

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Felipe Rodrigues
Hi Rawmin, Have you considered using MyPy (http://mypy-lang.org/)? Best, [image: --] Felipe V. Rodrigues [image: https://]about.me/fvr On Sat, Aug 22, 2020 at 9:58 AM wrote: > I wanted to know if there could be TypeError when giving wrong type for > ar

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Ronald Oussoren via Python-ideas
> On 22 Aug 2020, at 15:00, rawmin...@gmail.com wrote: > > I wanted to know if there could be TypeError when giving wrong type for > arguments in functions > (This usually happens when using other module's function) > > e.g: > > def sum(nom1: int, nom2: int): > nom = nom1 + nom2 > ret

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread rawmin . rx
No. I wanted to know if they can add this suggestion in next versions ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Me

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Richard Damon
On 8/22/20 10:34 AM, rawmin...@gmail.com wrote: > No. I wanted to know if they can add this suggestion in next versions It has been decided that Python will NOT enforce type annotations itself. There are modules where you can add an annotation to your function to add the checking yourself. -- R

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread rawmin . rx
Oh OK Thank you. But just a question: do you know any of these modules? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Eric Fahlgren
On Sat, Aug 22, 2020 at 7:37 AM wrote: > No. I wanted to know if they can add this suggestion in next versions > That will not happen. You may want to familiarize yourself with the intent of type annotations: https://www.python.org/dev/peps/pep-0526/#non-goals https://www.python.org/dev/peps/pe

[Python-ideas] Re: raise TypeError when giving wrong type of argument in functions

2020-08-22 Thread Richard Damon
On 8/22/20 11:59 AM, rawmin...@gmail.com wrote: > Oh OK Thank you. > But just a question: do you know any of these modules? The other thread someone suggested: https://github.com/agronholm/typeguard https://github.com/FelixTheC/strongtyping/issues/33 https://github.com/seandstewart/typical/issues

[Python-ideas] Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Stephen J. Turnbull
Oz writes: > With a go like parsing it would be: > ``` > >>> datetime.parse_duration("2w50d8h5m27s10ms2000us") -1 I see no need for this, and minutes vs. months are ambiguous. Especially with denormalized input as above, it's quite unreadable compared to the timedelta constructor with keywo

[Python-ideas] Re: Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Richard Damon
On 8/22/20 1:07 PM, Stephen J. Turnbull wrote: > If anything is to be added, I would prefer using ISO 8601 durations. > > https://en.wikipedia.org/wiki/ISO_8601#Durations > > The main differences are use of "P" and "T" to signal that it is a > duration and allow both minutes and months to be identi

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-22 Thread Christopher Barker
On Thu, Aug 20, 2020 at 9:16 PM Random832 wrote: > On Thu, Aug 20, 2020, at 20:09, Steven D'Aprano wrote: > > This is likely to be a rare and unusual case, but we don't want to break > > anyone who already has a dunder something like this: > > > > def __getitem__(self, index, extra=None) > >

[Python-ideas] Re: Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Christopher Barker
On Sat, Aug 22, 2020 at 10:29 AM Richard Damon wrote: > On 8/22/20 1:07 PM, Stephen J. Turnbull wrote: > > If anything is to be added, I would prefer using ISO 8601 durations. > > > > https://en.wikipedia.org/wiki/ISO_8601#Durations > > > > The main differences are use of "P" and "T" to signal th

[Python-ideas] Re: Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Alex Hall
On Sat, Aug 22, 2020 at 7:29 PM Richard Damon wrote: > On 8/22/20 1:07 PM, Stephen J. Turnbull wrote: > > If anything is to be added, I would prefer using ISO 8601 durations. > > > > https://en.wikipedia.org/wiki/ISO_8601#Durations > > > > The main differences are use of "P" and "T" to signal tha

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-22 Thread Guido van Rossum
The worst that could happen would be that some user figures out they can access the hidden functionality by writing a[key, extra=“stuff”], whereas previously they would have to call a.__getitem__(key, extra=“stuff”). Doesn’t sound like a big deal, and not breakage either. On Sat, Aug 22, 2020 at

[Python-ideas] Re: Add parse_duration to datetime - a golang like fucntion to parse duration

2020-08-22 Thread Christopher Barker
On Sat, Aug 22, 2020 at 10:29 AM Richard Damon wrote: One issue with allowing Months here is then suddenly an interval becomes > dependent on when it is, so needs to be keep in a complex form, as a > month (and year) are variable length time units. > months are already not supported by timedelta

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-22 Thread Christopher Barker
On Sat, Aug 22, 2020 at 11:22 AM Guido van Rossum wrote: > The worst that could happen would be that some user figures out they can > access the hidden functionality by writing a[key, extra=“stuff”], whereas > previously they would have to call a.__getitem__(key, extra=“stuff”). > > Doesn’t sound

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Christopher Barker
On Sat, Aug 22, 2020 at 12:11 AM Random832 wrote: > I think there are two possible paths here: either always print a warning > [not an error] when importing a module from the current directory [the > first entry in sys.path] that is also available in any other entry in > sys.path, This would be

[Python-ideas] Re: Custom keywords (from: Decorators for class non function properties)

2020-08-22 Thread redradist
Actually, I would like to write a proposal ... It would be nice if someone support me with it because I will do it at first time ... ) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
I agree — having a warning would be fantastic! Personally, I think the minor speed drawback of checking the full path would be worth it, in most cases. The fact that a module is being shadowed is really valuable information to have. If there’s enough of a demand for this, which I think there is,

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Chris Angelico
On Sun, Aug 23, 2020 at 10:14 AM Gustav O wrote: > > I agree — having a warning would be fantastic! Personally, I think the minor > speed drawback of checking the full path would be worth it, in most cases. > The fact that a module is being shadowed is really valuable information to > have. >

[Python-ideas] Re: Custom keywords (from: Decorators for class non function properties)

2020-08-22 Thread Steven D'Aprano
On Sat, Aug 22, 2020 at 10:50:28PM -, redrad...@gmail.com wrote: > Actually, I would like to write a proposal ... > It would be nice if someone support me with it because I will do it at first > time ... ) Okay, the first step is to familiarise yourself with the way the PEPs are written: ht

[Python-ideas] Re: Custom keywords (from: Decorators for class non function properties)

2020-08-22 Thread Steven D'Aprano
On Tue, Aug 18, 2020 at 07:39:29AM +0200, Marco Sulla wrote: > For example, many py programmers desider to make their objects a > constant. This could be done in the example I wrote before: > > from mykeywords import @const > @const a = 1 > > The new `@const` will be added as a hook to the PEG p

[Python-ideas] Re: Custom keywords (from: Decorators for class non function properties)

2020-08-22 Thread Chris Angelico
On Sun, Aug 23, 2020 at 10:29 AM Steven D'Aprano wrote: > After discussion here, if there are people interested and in favour of > the idea, then you can ask for somebody to sponsor a PEP. Ideally you > will have overwhelming support and everyone says "that's a great idea, > let's do it!" but more

[Python-ideas] Re: Custom keywords (from: Decorators for class non function properties)

2020-08-22 Thread Guido van Rossum
It's unlikely that any proposal for importing syntax macros will be accepted, let alone one as poorly thought-out as this one. The only reason for advising to attempt to write a more formal proposal in this case would be to cause the volunteer to realize just how poorly prepared they are for propos

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
It seems like most of us agree that the speed drawbacks wouldn’t be worth it — which I find understandable. If my understanding of excepthooks is correct, and that it’s the place to put code that should be executed once an AttributeError is raised, it sounds like a great solution. However, Att

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Chris Angelico
On Sun, Aug 23, 2020 at 11:02 AM Gustav O wrote: > > It seems like most of us agree that the speed drawbacks wouldn’t be worth it > — which I find understandable. > > If my understanding of excepthooks is correct, and that it’s the place to put > code that should be executed once an AttributeErr

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
In your answer, it sounds like the code would be written by the person developing a program. Or they could possibly have the importhook a separate module, which can be imported whenever you’d like to have it. Maybe I misunderstood you, but this wouldn’t really be optimal. I think most people wo

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Chris Angelico
On Sun, Aug 23, 2020 at 11:19 AM Gustav O wrote: > > In your answer, it sounds like the code would be written by the person > developing a program. Or they could possibly have the importhook a separate > module, which can be imported whenever you’d like to have it. > > Maybe I misunderstood you,

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
Alright! I’ll sure take a look at that. I also think adding it to the core language would be greatly beneficial. Just like Christopher said, this is one of those "gotchas". I’m still new to this process, but do you think that writing a PEP for this would be a reasonable next step? _

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Chris Angelico
On Sun, Aug 23, 2020 at 11:44 AM Gustav O wrote: > > Alright! I’ll sure take a look at that. > > I also think adding it to the core language would be greatly beneficial. Just > like Christopher said, this is one of those "gotchas". > > I’m still new to this process, but do you think that writing

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Gustav O
Alright, thanks for the help. You’ll probably see an implementation in a new thread here soon again. :) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-22 Thread Christopher Barker
On Sat, Aug 22, 2020 at 5:19 PM Chris Angelico wrote: > On Sun, Aug 23, 2020 at 10:14 AM Gustav O wrote: > > > > > > I agree — having a warning would be fantastic! Personally, I think the > minor speed drawback of > A speed drawback on every import would almost certainly be too high a > > pr