All fields

“Decorators” in Information Technology

45 questions across 2 technologies.

Information Technology

45 questions in 2 technologies

#QuestionTechnologyTopicLevel
1In what order do multiple decorators applied to the same declaration execute? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
2How do parameter decorators work, and what is a common real-world use for them? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
3How do the newer, TC39 'Stage 3' decorators differ from TypeScript's legacy experimentalDecorators implementation? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
4Why can decorators make code harder to statically analyze or tree-shake, and what's a common criticism of overusing them? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
5How do you stack MULTIPLE decorators on the same function, and in what order do they actually execute? Python › DecoratorsPythonDecoratorsAdvanced
6How does @functools.wraps preserve metadata when writing decorators? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsIntermediate
7How would you implement a function that dynamically inspects its own call arguments at runtime using the 'inspect' module, useful for building generic validation or logging decorators? Python › Functions & ScopePythonFunctions & ScopeAdvanced
8What is a decorator in TypeScript, and what does the @ syntax mean? TypeScript › DecoratorsTypeScriptDecoratorsBeginner
9What must be enabled in tsconfig.json to use the (legacy, 'experimental') decorator syntax? TypeScript › DecoratorsTypeScriptDecoratorsBeginner
10What is a decorator, and how does the @decorator_name syntax relate to a plain function call? Python › DecoratorsPythonDecoratorsBeginner
11How do you write a basic decorator that adds a print statement before and after calling the decorated function? Python › DecoratorsPythonDecoratorsBeginner
12How does a class decorator work, and what can it do to the class it's applied to? TypeScript › DecoratorsTypeScriptDecoratorsIntermediate
13How does a method decorator work, and what can it access via the PropertyDescriptor? TypeScript › DecoratorsTypeScriptDecoratorsIntermediate
14What is a decorator factory, and why would you use one instead of a plain decorator function? TypeScript › DecoratorsTypeScriptDecoratorsIntermediate
15Why should you use functools.wraps when writing a decorator, and what problem does it solve? Python › DecoratorsPythonDecoratorsIntermediate
16How do you write a decorator that itself accepts arguments, like @retry(times=3)? Python › DecoratorsPythonDecoratorsIntermediate
17How do you write a decorator as a CLASS instead of a function, implementing __call__? Python › DecoratorsPythonDecoratorsIntermediate
18How do you use functools.lru_cache to add memoization to a function with a single decorator? Python › DecoratorsPythonDecoratorsIntermediate
19How does a property decorator differ from a method decorator in what it receives and what it can do? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
20How do you write a decorator that works correctly on BOTH regular functions and methods (instance methods) of a class? Python › DecoratorsPythonDecoratorsAdvanced
21How would you implement a caching/memoization decorator from scratch, similar to functools.lru_cache? Python › DecoratorsPythonDecoratorsAdvanced
22How does functools.singledispatch let you implement function overloading based on an argument's TYPE? Python › DecoratorsPythonDecoratorsAdvanced
23How would you write a decorator that validates a function's arguments against its type hints at RUNTIME, since Python doesn't enforce type hints by default? Python › DecoratorsPythonDecoratorsAdvanced
24How do you preserve a decorated function's original SIGNATURE (parameter names, defaults) for introspection tools, beyond what functools.wraps alone provides? Python › DecoratorsPythonDecoratorsAdvanced
25How would you implement a thread-safe caching decorator that correctly handles concurrent calls from multiple threads? Python › DecoratorsPythonDecoratorsAdvanced
26How do you write a decorator that works correctly on an async function (coroutine), given that a regular decorator's wrapper would break 'await' usage? Python › DecoratorsPythonDecoratorsAdvanced
27How would you build a decorator-based plugin/registration system, similar to how Flask's @app.route() registers view functions? Python › DecoratorsPythonDecoratorsAdvanced
28What does it mean that functions are 'first-class objects' in Python? Python › Functions & ScopePythonFunctions & ScopeBeginner
29What is the functools module used for in Python? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsBeginner
30How do you use functools.partial to fix keyword arguments for logging or callback functions? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsBeginner
31Why do most Python developers rarely need to write a custom metaclass in everyday code? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationBeginner
32How does @contextlib.contextmanager let you write a context manager using a generator function instead of a full class? Python › File I/O & Context ManagersPythonFile I/O & Context ManagersIntermediate
33How do *args and **kwargs let a function accept an arbitrary number of positional and keyword arguments? Python › Functions & ScopePythonFunctions & ScopeIntermediate
34How does functools.partial work and when is it useful? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsIntermediate
35How does __call__ let an instance of a class be invoked like a function? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
36How do you create a class dynamically using type() with three arguments instead of a class statement? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationIntermediate
37How does __init_subclass__ provide a simpler alternative to metaclasses for many customization needs? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationIntermediate
38What is the difference between a class decorator and a metaclass for customizing class behavior? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationIntermediate
39How would you implement an async context manager that also supports being used as a decorator, similar to contextlib.contextmanager's decorator support? Python › Async Generators & Async Context ManagersPythonAsync Generators & Async Context ManagersAdvanced
40How would you implement a retry-with-backoff decorator that catches specific transient exceptions and retries with increasing delays? Python › Exception HandlingPythonException HandlingAdvanced
41How would you write a reusable context manager decorator using contextlib.contextmanager that ALSO works when applied directly to a function, like @contextmanager-decorated functions support? Python › File I/O & Context ManagersPythonFile I/O & Context ManagersAdvanced
42How does functools.singledispatch enable function overloading based on argument type? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsAdvanced
43How can functools.lru_cache be used with typed=True, and what does that change? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsAdvanced
44How do you write a custom metaclass by subclassing type, and when would you do so? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationAdvanced
45How does importlib let you dynamically import a module by name at runtime? Python › Modules & PackagingPythonModules & PackagingAdvanced