Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what can i uuse ... for?
#1
i have a function with an argument that needs to be highly flexible. it already has various cases for ints and strings and True and False. i am wondering if i can also use ... as a caller provided value, is it safe?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
You haven't shown any code, but it sounds like your function is quite complex if it has to handle all these different cases. Perhaps polymorphism, whether with classes, or e.g. functools.singledispatch would be a better design?
Gribouillis likes this post
Reply
#3
Syntactically, you cannot use ... where a name is expected, but the value ... or Ellipsis can be passed to a function call. It is an object like any other Python object.
Reply
#4
(Mar-07-2022, 07:27 AM)ndc85430 Wrote: You haven't shown any code,
the function is very large and would easily divert people off topic. there would be a lot of distracting talk about other aspects of the code.
(Mar-07-2022, 07:48 AM)Gribouillis Wrote: Syntactically, you cannot use ... where a name is expected, but the value ... or Ellipsis can be passed to a function call. It is an object like any other Python object.
i was thinking of using it as a value being passed and then in the function, checking for it like:
if foo is ...:
or:
if foo is Ellipsis:
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
That the function is very large is another sign that it does too much. Sure, it probably would obscure the important stuff to those reading on the forum. In several months, it'll also be more opaque to you. You'd benefit from the ideas in Uncle Bob's Clean Code. The "step down" rule is particularly useful.
Reply
#6
and the function is a "work in progress".
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
When do you refactor? If you're doing test-driven development, for example, the refactor step is right after getting the test to pass. I feel like test after doesn't give you the same kind of rhythm.
Reply
#8
are we changing the topic of this thread or starting a new one?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020