benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf accc6a2f-47f8-52b8-882c-f16d0da6fe0c

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import json
from datetime import datetime
from decimal import Decimal

def task_func(my_obj):
    """
    Serializes an object to a JSON string, adding support for datetime and Decimal data types.
    
    Handle complex data types not natively supported by the json module's default encoder. The `My_class` parameter is reserved for future use and does 
    not affect the current implementation.
    
    Parameters:
    - my_obj (object): The object to serialize, can include complex types such as datetime and Decimal.
    
    Returns:
    - str: A JSON-formatted string representing `my_obj`, with datetime and Decimal objects properly serialized.
        
    Requirements:
    - json
    - datetime.datetime
    - decimal.Decimal
    
    Examples:
    Serialize a dictionary containing datetime and Decimal:
    >>> result = task_func({'time': datetime(2023, 4, 1, 12, 0), 'amount': Decimal('10.99')})
    >>> '2023-04-01T12:00:00' in result and '10.99' in result
    True

    Serialize a simple dictionary:
    >>> task_func({'name': 'Alice', 'age': 30})
    '{"name": "Alice", "age": 30}'
    """

instruct prompt

Serializes an object to a JSON string, adding support for datetime and Decimal data types. Handle complex data types not natively supported by the json module's default encoder. The `My_class` parameter is reserved for future use and does not affect the current implementation. Serialize a simple dictionary: >>> task_func({'name': 'Alice', 'age': 30}) '{"name": "Alice", "age": 30}'
The function should output with:
    str: A JSON-formatted string representing `my_obj`, with datetime and Decimal objects properly serialized.
You should write self-contained code starting with:

Code

import json
from datetime import datetime
from decimal import Decimal
def task_func(my_obj):

code prompt

Code

import json
from datetime import datetime
from decimal import Decimal
def task_func(my_obj):

entry point

task_func

libs

  • decimal
  • datetime
  • json

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import