Python Forum

Full Version: what can i uuse ... for?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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?
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.
(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:
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.
and the function is a "work in progress".
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.
are we changing the topic of this thread or starting a new one?